import logging
import json

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from fidoweb.lib.base import Session, BaseController, render
from fidoweb.model.homepageGalleryPic import *

log = logging.getLogger(__name__)

class HomepageController(BaseController) :
	_mainPages = {
		'map' : '/homepage/mainpage_map.mako',
		'maploc' : '/homepage/mainpage_maploc.mako',
		'myloc' : '/homepage/mainpage_myloc.mako'
	}
	
	def index(self, id = '') :
		from fidoweb.controllers.login import LoginController
		from fidoweb.controllers.map import MapController
		lc = LoginController()
		mc = MapController()
		c.loginUser = lc._getLoginUser()
		if (c.loginUser != None) :
			redirect('login')
			return
		c.schools = mc._getSchools()
		
		c.jsFiles = list()
		c.cssFiles = list()
		c.title = 'Fido - Welcome'
		return render('homepage/content.mako')
	
	def getLeftNavPage(self) :
		from fidoweb.controllers.login import LoginController
		lc = LoginController()
		if (lc._isLoggedIn()) :
			return render('/homepage/leftnav_loggedin.mako')
		else :
			return render('/homepage/leftnav_loggedout.mako')
	
	def getMainPage(self) :
		if (not 'page' in request.POST) : return ''
		page = request.POST['page']
		if (self._mainPages.get(page) == None) :
			return ''
		else :
			return render(self._mainPages[page])
	
